rolesystem.jade.server
Class PermissionMatrix

java.lang.Object
  extended by rolesystem.jade.server.PermissionMatrix
All Implemented Interfaces:
java.io.Serializable

public class PermissionMatrix
extends java.lang.Object
implements java.io.Serializable

This class represents permissions of interactions between roles.

See Also:
Serialized Form

Nested Class Summary
static class PermissionMatrix.PMException
          Exception of this class are thrown by methods of class PermissionMatrix.
 
Constructor Summary
PermissionMatrix()
          Constructs a default matrix, with no known roles.
 
Method Summary
 void addRole(java.lang.String role)
          Adds a new role to the known ones.
 boolean checkPermission(java.lang.String senderRole, java.lang.String addresseeRole)
          Checks whether interactions between the specified roles are allowed.
 void copy(PermissionMatrix original)
          Copies this permission matrix from a specified one.
 java.lang.String[] getKnownRoles()
          Gets an array filled with all known roles.
 void removeRole(java.lang.String role)
          Removes a role from the known ones.
 void setPermission(java.lang.String senderRole, java.lang.String addresseeRole, boolean allow)
          Sets permission for interactions between the specified roles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PermissionMatrix

public PermissionMatrix()
Constructs a default matrix, with no known roles. Interactions between unknown roles are allowed by default.

Method Detail

copy

public void copy(PermissionMatrix original)
Copies this permission matrix from a specified one.

Parameters:
original - Permission matrix to copy.

addRole

public void addRole(java.lang.String role)
             throws PermissionMatrix.PMException
Adds a new role to the known ones. Permissions related to the new role are copied from the ones related to unknown roles.

Parameters:
role - Role to add.
Throws:
PermissionMatrix.PMException - If the specified role already exists.

removeRole

public void removeRole(java.lang.String role)
                throws PermissionMatrix.PMException
Removes a role from the known ones.

Parameters:
role - Role to remove.
Throws:
PermissionMatrix.PMException - If the specified role does not exist.

checkPermission

public boolean checkPermission(java.lang.String senderRole,
                               java.lang.String addresseeRole)
Checks whether interactions between the specified roles are allowed.

Parameters:
senderRole - Role of the sender.
addresseeRole - Role of the addressee.
Returns:
true if interactions are allowed, false otherwise.

setPermission

public void setPermission(java.lang.String senderRole,
                          java.lang.String addresseeRole,
                          boolean allow)
                   throws PermissionMatrix.PMException
Sets permission for interactions between the specified roles.

Parameters:
senderRole - Role of the sender; null indicates all unknown roles.
addresseeRole - Role of the addressee; null indicates all unknown roles.
allow - true if interactions must be allowed, false otherwise.
Throws:
PermissionMatrix.PMException - If one or both of specified roles is not known.

getKnownRoles

public java.lang.String[] getKnownRoles()
Gets an array filled with all known roles.

Returns:
An array filled with all known roles.